

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 运行环境 windows10 IDEA 专业版  笔者的资源分享：  前端模板 链接：点击下载 后端模板 链接：点击下载  提取码均为：unir  1. 前言 由于疫情原因，期末考试提前，笔者现在只能尽快赶时间，完成一些大作业。 根据几天构思，笔者打算在web期末课设中选”购物网站” 相关的主题，实现简单的发布商品、购买商品等功能，以下是笔者做课设的一些记录。 web开发如果用HTM">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆">
<meta property="og:url" content="http://example.com/2021/12/19/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%B8%80%EF%BC%89%20_%20%E5%A4%A7%E5%AD%A6%E7%94%9F%E9%97%B2%E7%BD%AE%E7%89%A9%E5%93%81%E4%BA%A4%E6%98%93%E7%B3%BB%E7%BB%9F%20_%20%E9%80%89%E6%8B%A9%E9%A1%B5%E9%9D%A2%E6%A8%A1%E6%9D%BF%EF%BC%88%E9%99%84%E8%B5%84%E6%BA%90%EF%BC%89%EF%BC%8C%E4%BD%BF%E7%94%A8%20JQuery%20AJAX%E5%AE%9E%E7%8E%B0%E6%B3%A8%E5%86%8C%E3%80%81%E7%99%BB%E9%99%86/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 运行环境 windows10 IDEA 专业版  笔者的资源分享：  前端模板 链接：点击下载 后端模板 链接：点击下载  提取码均为：unir  1. 前言 由于疫情原因，期末考试提前，笔者现在只能尽快赶时间，完成一些大作业。 根据几天构思，笔者打算在web期末课设中选”购物网站” 相关的主题，实现简单的发布商品、购买商品等功能，以下是笔者做课设的一些记录。 web开发如果用HTM">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/69fc71169f1d4711acb4510b6ec760c7.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c0b4d597b7974bf294b1eff5ce7e16c2.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e83cf24aa58c4198bdaacb57cc7bfbb5.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e6f9347fe0f9425ca00110efc08a11a3.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f55746c3e0ed4213bb8f83336da4dfdb.png">
<meta property="article:published_time" content="2021-12-19T13:20:46.000Z">
<meta property="article:modified_time" content="2022-08-22T15:50:34.382Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v1.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/69fc71169f1d4711acb4510b6ec760c7.png#pic_center">
  
  
  
  <title>Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-12-19 21:20" pubdate>
          2021年12月19日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          11k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          90 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><ul>
<li>windows10</li>
<li>IDEA 专业版</li>
</ul>
<p>笔者的资源分享：</p>
<ul>
<li>前端模板 链接：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1aSonJF89fyWe3sQN6UwCnQ">点击下载</a></li>
<li>后端模板 链接：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1VcR2c7jV-dg34700i5gcoQ">点击下载</a></li>
</ul>
<p>提取码均为：<code>unir </code></p>
<h1 id="1-前言"><a href="#1-前言" class="headerlink" title="1. 前言"></a>1. 前言</h1><hr>
<p>由于疫情原因，期末考试提前，笔者现在只能尽快赶时间，完成一些大作业。</p>
<p>根据几天构思，笔者打算在web期末课设中选”购物网站” 相关的主题，实现简单的发布商品、购买商品等功能，以下是笔者做课设的一些记录。</p>
<p>web开发如果用HTML、CSS、JS三大件直接从零开始写页面就会非常耗时间，且意义并不大。</p>
<p>现有许多的Web开发的相关框架，前端的有 Vue.js、React.js、JqueryBootstrap、ElementUI等，</p>
<p>后端的有SSM、SpringBoot等。</p>
<p>基于现学习阶段，本学期初次入门JavaWeb主要学习了HTML、CSS、JavaScript、JQuery、JDBC、JSP、Servlet、Cookie和Session、监听器和过滤器、AJAX等多项技术。</p>
<p>在平时的实验里对相应的技术有所熟悉，现综合这些技术，开发一个 “ 闲优购 “ 的平台，预期开发时间: 7 天</p>
<h1 id="2-挑选模板"><a href="#2-挑选模板" class="headerlink" title="2. 挑选模板"></a>2. 挑选模板</h1><hr>
<p>模板的选型比较重要，因为它决定了具体要实现的功能。</p>
<p>经过搜查资料，笔者选择的模板如下：</p>
<h2 id="2-1-前端模板"><a href="#2-1-前端模板" class="headerlink" title="2.1 前端模板"></a>2.1 前端模板</h2><p>前端的网页模板用于显示用户操作页面，比如注册、登陆、挑选商品、发布商品、管理个人信息等功能。</p>
<p><code>登陆页面</code><br><img src="https://img-blog.csdnimg.cn/69fc71169f1d4711acb4510b6ec760c7.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><code>主页面</code><br><img src="https://img-blog.csdnimg.cn/c0b4d597b7974bf294b1eff5ce7e16c2.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-2-后端模板"><a href="#2-2-后端模板" class="headerlink" title="2.2 后端模板"></a>2.2 后端模板</h2><p>后端模板用于管理员设置，比如修改某个订单的状态，查询所有用户的订单交易额等。</p>
<p><img src="https://img-blog.csdnimg.cn/e83cf24aa58c4198bdaacb57cc7bfbb5.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-3-总结"><a href="#2-3-总结" class="headerlink" title="2.3 总结"></a>2.3 总结</h2><p>在基于前端模板的前提，先由浅入深实现用户的基本功能，比如注册、登陆、修改等。</p>
<p>后端模板应放在最后的阶段，因为在本学期课程设计中，并没有强制要求设置管理员的模块实现。</p>
<h1 id="3-实现注册与登陆"><a href="#3-实现注册与登陆" class="headerlink" title="3. 实现注册与登陆"></a>3. 实现注册与登陆</h1><h2 id="3-1-项目结构"><a href="#3-1-项目结构" class="headerlink" title="3.1 项目结构"></a>3.1 项目结构</h2><p>笔者后端用到的项目结构: MVC模型<br><img src="https://img-blog.csdnimg.cn/e6f9347fe0f9425ca00110efc08a11a3.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>具体作用描述如下：</p>
<table>
<thead>
<tr>
<th align="left">模块名称</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">dao</td>
<td align="left">数据访问层,全称为data access object, 负责与数据库简单交互</td>
</tr>
<tr>
<td align="left">service</td>
<td align="left">服务层，负责使用dao层的功能去实现一些业务</td>
</tr>
<tr>
<td align="left">servlet</td>
<td align="left">请求与响应层， 负责使用service层的功能去实现前端的请求</td>
</tr>
<tr>
<td align="left">filter</td>
<td align="left">过滤器层，负责过滤页面或者servlet，这里用于修改servlet请求的编码格式以及非登陆用户对其他页面的访问</td>
</tr>
<tr>
<td align="left">entity</td>
<td align="left">存放实体类，用于表示某个实体的具体类，比如用户、商品等实体</td>
</tr>
<tr>
<td align="left">utils</td>
<td align="left">工具类，存放一些工具性质的操作类，里面一般是一些static静态的方法，可通过类名直接调用，目前只有数据库的操作类</td>
</tr>
</tbody></table>
<hr>
<h2 id="3-2-注册"><a href="#3-2-注册" class="headerlink" title="3.2 注册"></a>3.2 注册</h2><p>首先观察前端注册页面 <code>register.html</code>，主要就是有一个表单，可以发现，当密码输入不规范时会有一个红色的提示</p>
<p><img src="https://img-blog.csdnimg.cn/f55746c3e0ed4213bb8f83336da4dfdb.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>在表单中的部分代码:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>用户名:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;user_name&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;user_name&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;error_tip&quot;</span>&gt;</span>提示信息<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>	<br></code></pre></td></tr></table></figure>
<p>提示信息 error_tip 是通过 JS代码进行控制的，只要输入框 失去了焦点，JS代码就会对输入框内容进行判断，从而显示出警告的信息。</p>
<p>接下来通过观察 <code>register.html</code> 页面引入的JS代码来查找 具体的JS实现代码部分</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;Content-Type&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;text/html;charset=UTF-8&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>天天生鲜-注册<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/css&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;css/reset.css&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/css&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;css/main.css&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;js/jquery-1.12.4.min.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;js/register.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>以上代码是 <code>register.html</code> 页面的 head标签部分，可以观察到它引入的是 <code>register.js</code></p>
<p>该代码模块主要是关于用户输入提示的内容，无需改动太多，】这里笔者采用的是将邮箱改成了联系方式，因为笔者做的课设主题没有用到邮箱这个字段，相应的js代码也要做改变，同时在 <code>register.html</code>页面中将表单里输入框的标签内的name属性修改成对应的，比如之前email输入框input组件的name属性值改为phone，这样在后端的servlet类才能获取到。</p>
<h3 id="3-2-1-JDBC连接池连接"><a href="#3-2-1-JDBC连接池连接" class="headerlink" title="3.2.1 JDBC连接池连接"></a>3.2.1 JDBC连接池连接</h3><p>JDBC的数据源是指JDBC提供与数据库连接的接口 <code>javax.sql.DataSource</code>，当在应用程序中访问数据库时，不必编写连接数据库的代码，直接引用DataSource对象获取连接的对象。</p>
<p>数据源的作用：</p>
<ul>
<li>建立多个数据库连接</li>
<li>自动回收空闲的连接</li>
</ul>
<p>JDBC连接池采用 阿里云的Druid连接池，即数据源。</p>
<p><code>dbpool.properties</code></p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs properties"><span class="hljs-attr">driverClassName</span>=<span class="hljs-string">com.mysql.jdbc.Driver</span><br><span class="hljs-attr">url</span>=<span class="hljs-string">jdbc:mysql://localhost:3306/web_end?useUnicode=true&amp;characterEncoding=UTF-8</span><br><span class="hljs-attr">username</span>=<span class="hljs-string">root</span><br><span class="hljs-attr">password</span>=<span class="hljs-string">数据库密码</span><br></code></pre></td></tr></table></figure>

<p><code>DruidUtils.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> utils;<br><br><span class="hljs-keyword">import</span> com.alibaba.druid.pool.DruidDataSource;<br><span class="hljs-keyword">import</span> com.alibaba.druid.pool.DruidDataSourceFactory;<br><br><span class="hljs-keyword">import</span> javax.xml.transform.Result;<br><span class="hljs-keyword">import</span> java.io.IOException;<br><span class="hljs-keyword">import</span> java.sql.Connection;<br><span class="hljs-keyword">import</span> java.sql.PreparedStatement;<br><span class="hljs-keyword">import</span> java.sql.ResultSet;<br><span class="hljs-keyword">import</span> java.sql.SQLException;<br><span class="hljs-keyword">import</span> java.util.Properties;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@author</span> Uni</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@create</span> 2021/12/18 11:49</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">DruidUtil</span> &#123;<br>    <span class="hljs-keyword">static</span> DruidDataSource dataSource;<br>    <span class="hljs-keyword">static</span> &#123;<br>        <span class="hljs-type">Properties</span> <span class="hljs-variable">prop</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Properties</span>();<br>        <span class="hljs-keyword">try</span>&#123;<br>            prop.load(DruidUtil.class.getClassLoader().getResourceAsStream(<span class="hljs-string">&quot;dbpool.properties&quot;</span>));<br>            dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(prop);<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>            e.printStackTrace();<br>        &#125;<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Connection <span class="hljs-title function_">getConnection</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">try</span>&#123;<br>            <span class="hljs-keyword">return</span> dataSource.getConnection();<br>        &#125; <span class="hljs-keyword">catch</span> (SQLException e)&#123;<br>            e.printStackTrace();<br>        &#125;<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">release</span><span class="hljs-params">(Connection connection, PreparedStatement pstmt, ResultSet rs)</span>&#123;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-keyword">if</span> (pstmt != <span class="hljs-literal">null</span>) pstmt.close();<br>            <span class="hljs-keyword">if</span> (rs != <span class="hljs-literal">null</span>) rs.close();<br>            <span class="hljs-keyword">if</span> (connection != <span class="hljs-literal">null</span>) connection.close();<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e)&#123;<br>            e.printStackTrace();<br>        &#125;<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<h3 id="3-2-2-dao层实现JDBC的判重、插入"><a href="#3-2-2-dao层实现JDBC的判重、插入" class="headerlink" title="3.2.2 dao层实现JDBC的判重、插入"></a>3.2.2 dao层实现JDBC的判重、插入</h3><p>注册之前需判断用户是否存在，笔者采用的方式是以<strong>不允许重复</strong>的phone字段进行判断，之后在实现插入的方法<br><code>UserDaoImpl.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> User <span class="hljs-title function_">queryByPhone</span><span class="hljs-params">(String phone)</span> &#123;<br>       <span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> DruidUtil.getConnection();<br>       <span class="hljs-type">String</span> <span class="hljs-variable">sql</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;select * from user where phone = ?&quot;</span>;<br>       <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>       <span class="hljs-keyword">try</span>&#123;<br>           <span class="hljs-type">PreparedStatement</span> <span class="hljs-variable">pstmt</span> <span class="hljs-operator">=</span> connection.prepareStatement(sql);<br>           pstmt.setString(<span class="hljs-number">1</span>, phone);<br>           <span class="hljs-type">ResultSet</span> <span class="hljs-variable">rs</span> <span class="hljs-operator">=</span> pstmt.executeQuery();<br>           <span class="hljs-keyword">while</span>(rs.next())&#123;<br>               user = <span class="hljs-keyword">new</span> <span class="hljs-title class_">User</span>(rs.getInt(<span class="hljs-number">1</span>),<br>                       rs.getString(<span class="hljs-number">2</span>),<br>                       rs.getString(<span class="hljs-number">3</span>),<br>                       rs.getString(<span class="hljs-number">4</span>));<br>           &#125;<br>           DruidUtil.release(connection, pstmt, rs);<br>       &#125; <span class="hljs-keyword">catch</span> (SQLException throwables) &#123;<br>           throwables.printStackTrace();<br>       &#125;<br>       <span class="hljs-keyword">return</span> user;<br>   &#125;<br>   <br>   <span class="hljs-meta">@Override</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">insertUser</span><span class="hljs-params">(User user)</span> &#123;<br>       <span class="hljs-type">Connection</span> <span class="hljs-variable">connection</span> <span class="hljs-operator">=</span> DruidUtil.getConnection();<br>       <span class="hljs-type">String</span> <span class="hljs-variable">sql</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;insert into user (name, password, phone) values (?, ?, ?)&quot;</span>;<br>       <span class="hljs-keyword">try</span> &#123;<br>           <span class="hljs-type">PreparedStatement</span> <span class="hljs-variable">pstmt</span> <span class="hljs-operator">=</span> connection.prepareStatement(sql);<br>           pstmt.setString(<span class="hljs-number">1</span>, user.getName());<br>           pstmt.setString(<span class="hljs-number">2</span>, user.getPassword());<br>           pstmt.setString(<span class="hljs-number">3</span>, user.getPhone());<br>           pstmt.execute();<br>           DruidUtil.release(connection, pstmt, <span class="hljs-literal">null</span>);<br>           <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br>       &#125; <span class="hljs-keyword">catch</span> (SQLException throwables) &#123;<br>           throwables.printStackTrace();<br>       &#125;<br>       <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>   &#125;<br></code></pre></td></tr></table></figure>

<p>为避免多个servlet请求重复定义Service层接口实现类，现定义一个类用于声明静态的service层接口实现类。</p>
<p><code>Service.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> service;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Service</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-type">UserService</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserServiceImpl</span>();<br>&#125;<br><br></code></pre></td></tr></table></figure>


<h3 id="3-2-3-设计实现注册的Servlet类代码"><a href="#3-2-3-设计实现注册的Servlet类代码" class="headerlink" title="3.2.3 设计实现注册的Servlet类代码"></a>3.2.3 设计实现注册的Servlet类代码</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> servlet;<br><br><span class="hljs-keyword">import</span> entity.User;<br><span class="hljs-keyword">import</span> service.Service;<br><span class="hljs-keyword">import</span> service.UserService;<br><span class="hljs-keyword">import</span> service.UserServiceImpl;<br><br><span class="hljs-keyword">import</span> javax.servlet.ServletException;<br><span class="hljs-keyword">import</span> javax.servlet.annotation.WebServlet;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServlet;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServletRequest;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServletResponse;<br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-meta">@WebServlet(name = &quot;UserRegisterServlet&quot;, urlPatterns = &quot;/toRegister&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserRegisterServlet</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">HttpServlet</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doGet</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException &#123;<br>        resp.getWriter().write(<span class="hljs-string">&quot;无法使用Get请求进行注册.&quot;</span>);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doPost</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">username</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;username&quot;</span>);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">password</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;password&quot;</span>);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">phone</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;phone&quot;</span>);<br>        <span class="hljs-type">User</span> <span class="hljs-variable">user_check</span> <span class="hljs-operator">=</span> Service.user.queryByPhone(phone);<br>        <span class="hljs-comment">// 当用户存在时</span><br>        <span class="hljs-keyword">if</span>(user_check != <span class="hljs-literal">null</span>) &#123;<br>            req.setAttribute(<span class="hljs-string">&quot;reg_error&quot;</span>, <span class="hljs-string">&quot;用户已存在&quot;</span>);<br>            req.getRequestDispatcher(<span class="hljs-string">&quot;register.html&quot;</span>).forward(req, resp);<br>        &#125; <span class="hljs-keyword">else</span>&#123;<br>            <span class="hljs-comment">// 注册操作</span><br>            <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">User</span>(username, password, phone);<br>            <span class="hljs-type">boolean</span> <span class="hljs-variable">state</span> <span class="hljs-operator">=</span> Service.user.registerUser(user);<br>            <span class="hljs-keyword">if</span>(state)&#123;<br>                <span class="hljs-comment">// 登陆</span><br>                req.getSession().setAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>, user);<br><span class="hljs-comment">//                System.out.println(&quot;session添加: &quot; + user); // 测试</span><br>            &#125; <span class="hljs-keyword">else</span>&#123;<br>                <span class="hljs-comment">// ... 注册操作失败时的处理</span><br>            &#125;<br>            resp.sendRedirect(<span class="hljs-string">&quot;index.jsp&quot;</span>);<br>        &#125;<br>    &#125;<br>&#125;<br><br><br></code></pre></td></tr></table></figure>

<p>至此，已完成了注册功能</p>
<h2 id="3-3-登陆"><a href="#3-3-登陆" class="headerlink" title="3.3 登陆"></a>3.3 登陆</h2><p>登陆功能笔者使用的是AJAX请求方式，同时熟悉了一下JQuery的AJAX操作，在这个前端模板要通过AJAX请求，需把按钮的属性type值从submit改成button，实现注册的JS代码</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs javascript">$(<span class="hljs-variable language_">document</span>).<span class="hljs-title function_">ready</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>   $(<span class="hljs-string">&quot;#login&quot;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>       <span class="hljs-keyword">var</span> username = $(<span class="hljs-string">&quot;#un&quot;</span>).<span class="hljs-title function_">val</span>();<br>       <span class="hljs-keyword">var</span> password = $(<span class="hljs-string">&quot;#pw&quot;</span>).<span class="hljs-title function_">val</span>();<br>      <br>       $.<span class="hljs-title function_">ajax</span>(&#123;<br>          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>          <span class="hljs-attr">url</span>: <span class="hljs-string">&quot;/toLogin?username=&quot;</span>+username + <span class="hljs-string">&quot;&amp;password=&quot;</span> + password,<br>          <span class="hljs-attr">async</span>: <span class="hljs-literal">false</span>,<br>          <span class="hljs-attr">error</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>             <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;操作失败&#x27;</span> + data)<br>          &#125;,<br>          <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">result</span>)&#123;<br>              <span class="hljs-keyword">if</span>(result == <span class="hljs-string">&quot;false&quot;</span>) &#123;<br>                  <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;登陆失败!&#x27;</span>)<br>                  <span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span>.<span class="hljs-property">href</span>=<span class="hljs-string">&quot;/login.html&quot;</span>;<br>              &#125;<br>              <span class="hljs-keyword">else</span><br>                  <span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span>.<span class="hljs-property">href</span>=<span class="hljs-string">&quot;/index.jsp&quot;</span>;<br>          &#125;<br>      &#125;);<br>   &#125;);<br>&#125;);<br></code></pre></td></tr></table></figure>

<p>至此，实现了登陆功能。</p>
<h1 id="4-Servlet过滤器"><a href="#4-Servlet过滤器" class="headerlink" title="4. Servlet过滤器"></a>4. Servlet过滤器</h1><hr>
<h2 id="4-1-防止servlet请求出现乱码，进行编码过滤"><a href="#4-1-防止servlet请求出现乱码，进行编码过滤" class="headerlink" title="4.1 防止servlet请求出现乱码，进行编码过滤"></a>4.1 防止servlet请求出现乱码，进行编码过滤</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@WebFilter(filterName = &quot;EncodingFilter&quot;, value=&quot;/toLogin&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">EncodingFilter</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Filter</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doFilter</span><span class="hljs-params">(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)</span><br>            <span class="hljs-keyword">throws</span> IOException, ServletException &#123;<br>        <span class="hljs-type">HttpServletRequest</span> <span class="hljs-variable">request</span> <span class="hljs-operator">=</span> (HttpServletRequest)  servletRequest;<br>        <span class="hljs-type">HttpServletResponse</span> <span class="hljs-variable">response</span> <span class="hljs-operator">=</span> (HttpServletResponse) servletResponse;<br>        request.setCharacterEncoding(<span class="hljs-string">&quot;utf-8&quot;</span>);<br>        response.setHeader(<span class="hljs-string">&quot;content-type&quot;</span>, <span class="hljs-string">&quot;text/html;charset=utf-8&quot;</span>);<br>        filterChain.doFilter(request, response);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="4-2-防止未登录用户访问首页"><a href="#4-2-防止未登录用户访问首页" class="headerlink" title="4.2 防止未登录用户访问首页"></a>4.2 防止未登录用户访问首页</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">LoginFilter</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Filter</span> &#123;<br><br>    <span class="hljs-comment">// 拦截未登陆用户访问首页</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doFilter</span><span class="hljs-params">(ServletRequest request, ServletResponse response, FilterChain fchain)</span> <span class="hljs-keyword">throws</span> IOException, ServletException &#123;<br>        <span class="hljs-type">HttpServletRequest</span> <span class="hljs-variable">req</span> <span class="hljs-operator">=</span> (HttpServletRequest) request;<br>        <span class="hljs-type">HttpServletResponse</span> <span class="hljs-variable">resp</span> <span class="hljs-operator">=</span> (HttpServletResponse) response;<br>        <span class="hljs-type">HttpSession</span> <span class="hljs-variable">session</span> <span class="hljs-operator">=</span> req.getSession();<br><br>        <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> (User) session.getAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>);<br><span class="hljs-comment">//        System.out.println(&quot;拦截器读取到用户的信息&quot; + user);</span><br>        <span class="hljs-keyword">if</span>(user == <span class="hljs-literal">null</span>)<br>            ((HttpServletResponse) response).sendRedirect(<span class="hljs-string">&quot;login.html&quot;</span>);<br>        <span class="hljs-keyword">else</span><br>            fchain.doFilter(request, response);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="5-总结"><a href="#5-总结" class="headerlink" title="5. 总结"></a>5. 总结</h1><hr>
<p>今天花时间找了两个模板，创建了MVC模型的Web项目，并通过AJAX请求方式实现了登陆，还有通过直接设置form表单的action属性实现注册，通过session来判断用户是否登陆等，以及简单的应用到了servlet的过滤器，还算是比较有收获的。但目前位置，还有许多工作待完成，接下来的几天需要赶一下进度了。</p>
<h1 id="下一部分"><a href="#下一部分" class="headerlink" title="下一部分"></a>下一部分</h1><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122035714">Web期末课程设计v1.0（二） | 大学生闲置物品交易系统 | 使用Bootstrap5各组件优化页面，使用AJAX请求实现用户修改信息功能</a></p>
<h2 id="附-项目pom-xml依赖"><a href="#附-项目pom-xml依赖" class="headerlink" title="附: 项目pom.xml依赖"></a>附: 项目pom.xml依赖</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>groupId<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>project<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>RELEASE<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>compile<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.37<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/com.alibaba/druid --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.8<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.13.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>javax.servlet.jsp.jstl<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>jstl-api<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.taglibs<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>taglibs-standard-impl<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">maven.compiler.source</span>&gt;</span>8<span class="hljs-tag">&lt;/<span class="hljs-name">maven.compiler.source</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">maven.compiler.target</span>&gt;</span>8<span class="hljs-tag">&lt;/<span class="hljs-name">maven.compiler.target</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span><br>    <br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1-0/" class="category-chain-item">项目实战:购物系统v1.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1-0/">#项目实战:购物系统v1.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆</div>
      <div>http://example.com/2021/12/19/Web项目实战 _ 购物系统v1.0 _ 开发记录（一） _ 大学生闲置物品交易系统 _ 选择页面模板（附资源），使用 JQuery AJAX实现注册、登陆/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年12月19日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/12/20/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%BA%8C%EF%BC%89%20_%20%E4%BD%BF%E7%94%A8Bootstrap5%E5%90%84%E7%BB%84%E4%BB%B6%E4%BC%98%E5%8C%96%E9%A1%B5%E9%9D%A2%EF%BC%8C%E4%BD%BF%E7%94%A8AJAX%E8%AF%B7%E6%B1%82%E5%AE%9E%E7%8E%B0%E7%94%A8%E6%88%B7%E4%BF%AE%E6%94%B9%E4%BF%A1%E6%81%AF%E5%8A%9F%E8%83%BD/" title="Web项目实战 _ 购物系统v1.0 _ 开发记录（二） _ 使用Bootstrap5各组件优化页面，使用AJAX请求实现用户修改信息功能">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v1.0 _ 开发记录（二） _ 使用Bootstrap5各组件优化页面，使用AJAX请求实现用户修改信息功能</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/12/16/Android%20_%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%20_%20AsyncTask%E7%B1%BB%20%E6%A6%82%E8%BF%B0%E5%8F%8A%E5%85%B6%E4%BD%BF%E7%94%A8/" title="Android _ 多线程 _ AsyncTask类 概述及其使用">
                        <span class="hidden-mobile">Android _ 多线程 _ AsyncTask类 概述及其使用</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
